public class ZooManager {
    package zoo;

import java.util.Scanner;


    public class ZooManager {
        // 对象数组
        Animal[] animals = new Animal[10];
        static Scanner input = new Scanner(System.in);


        public ZooManager() {
            animals[0] = new Cat("汤姆猫", 4);
            animals[1] = new Duck("大黄鸭", 2);
            animals[2] = new Snake("赖皮蛇");
            animals[3] = new Fish("鱼");
        }

        /
        public void seeCat() {// 看貓。
            for (int i = 0; i < animals.length; i++) {
                if (animals[i] != null && animals[i] instanceof Cat) {// 查看貓
                    ILeg leg = new Cat();
                    System.out.print(animals[i].getName() + "\t" + leg.getLegNum() + "\t");
                    animals[i].shout();
                }
            }
        }

        public void seeFish() {// 看鱼
            for (int i = 0; i < animals.length; i++) {
                if (animals[i] != null && animals[i] instanceof Fish) {// 查看鱼
                    System.out.print(animals[i].getName() + "\t");
                    animals[i].shout();
                }
            }
        }

        public void seeDuck() {// 看鸭子
            for (int i = 0; i < animals.length; i++) {
                if (animals[i] != null && animals[i] instanceof Duck) {// 查看鴨子
                    ILeg leg = new Duck();
                    System.out.print(animals[i].getName() + "\t" + leg.getLegNum() + "\t");
                    animals[i].shout();
                }
            }
        }

        public void seeSnake() {// 看蛇
            for (int i = 0; i < animals.length; i++) {
                if (animals[i] != null && animals[i] instanceof Snake) {// 查看蛇
                    System.out.print(animals[i].getName() + "\t" + "\t");
                    animals[i].shout();
                }
            }
        }


        public boolean isOut() {
            if (animals[animals.length - 1] != null) {
                System.out.println("动物已经添加满了，不能再继续添加了。");
                return false;
            } else {
                return true;
            }
        }


        public int seekCat() {// 找猫
            System.out.println("请输入你要操作的猫的名字：");
            String name = input.next();
            for (int i = 0; i < animals.length; i++) {
                if (animals[i] != null) {
                    if (animals[i].getName().equals(name) && animals[i] instanceof Cat) {
                        return i;
                    } else {
                        continue;
                    }
                }
                System.out.println("找不到猫");
                return -1;
            }
            System.out.println("找不到猫");
            return -1;
        }

        public int seekDuck() {// 找鸭子
            System.out.println("请输入你要操作的鸭子的名字：");
            String name = input.next();
            for (int i = 0; i < animals.length; i++) {
                if (animals[i] != null) {
                    if (animals[i].getName().equals(name) && animals[i] instanceof Duck) {
                        return i;
                    } else {
                        continue;
                    }
                }
                System.out.println("找不到鸭子");
                return -1;
            }
            System.out.println("找不到鸭子");
            return -1;
        }

        public int seekSnake() {// 找蛇
            System.out.println("请输入你要操作的蛇的名字：");
            String name = input.next();
            for (int i = 0; i < animals.length; i++) {
                if (animals[i] != null) {
                    if (animals[i].getName().equals(name) && animals[i] instanceof Snake) {
                        return i;
                    } else {
                        continue;
                    }
                }
                System.out.println("找不到蛇");
                return -1;
            }
            System.out.println("找不到蛇");
            return -1;
        }

        public int seekFish() {// 找鱼
            System.out.println("请输入你要操作的鱼的名字：");
            String name = input.next();
            for (int i = 0; i < animals.length; i++) {
                if (animals[i] != null) {
                    if (animals[i].getName().equals(name) && animals[i] instanceof Fish) {
                        return i;
                    } else {
                        continue;
                    }
                }
                System.out.println("找不到鱼");
                return -1;
            }
            System.out.println("找不到鱼");
            return -1;
        }


        public void addCat() {// 加猫
            String name = input.next();
            for (int i = 0; i < animals.length; i++) {
                if (animals[i] == null) {
                    animals[i] = new Cat(name, 4);// 初始的腿是4条。
                    break;
                }
            }

        }

        public void addDuck() {// 加鸭子
            String name = input.next();
            for (int i = 0; i < animals.length; i++) {
                if (animals[i] == null) {
                    animals[i] = new Duck(name, 2);// 初始的腿是2条。
                    break;
                }
            }
        }

        public void addSnake() {// 加蛇
            String name = input.next();
            for (int i = 0; i < animals.length; i++) {
                if (animals[i] == null) {
                    animals[i] = new Snake(name);
                    break;
                }
            }
        }

        public void addFish() {// 加鱼
            String name = input.next();
            for (int i = 0; i < animals.length; i++) {
                if (animals[i] == null) {
                    animals[i] = new Fish(name);
                    break;
                }
            }
        }


        public void delCat() {// 删除猫
            int i = seekCat();// 找到目标的猫，返回下标，没找到时，i = -1
            if (i != -1) {
                for (int j = i; j < animals.length - 1; j++) {
                    if (animals[j] != null) {
                        animals[j] = animals[j + 1];
                    }

                }
                System.out.println("删除成功！你现在就能去查看！");
            }

        }

        public void delDuck() {// 删除鸭子
            int i = seekDuck();
            if (i != -1) {
                for (int j = i; j < animals.length - 1; j++) {
                    animals[j] = animals[j + 1];
                }

            }
            System.out.println("删除成功！你现在就能去查看！");

        }

        public void delSnake() {// 删除蛇
            int i = seekSnake();
            if (i != -1) {
                for (int j = i; j < animals.length - 1; j++) {
                    animals[j] = animals[j + 1];
                }

            }
            System.out.println("删除成功！你现在就能去查看！");
        }

        public void delFish() {// 删除鱼
            int i = seekFish();
            if (i != -1) {
                for (int j = i; j < animals.length - 1; j++) {
                    animals[j] = animals[j + 1];
                }

            }
            System.out.println("删除成功！你现在就能去查看！");
        }



    }




}
